package com.happyrecyclingstation.controller.hr;

import com.happyrecyclingstation.constant.MessageConstant;
import com.happyrecyclingstation.service.UserService;
import com.happyrecyclingstation.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 企业用户
 */
@Slf4j
@RequestMapping("/hr/users")
@RestController("hrUserController")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 查询hr是否关联了企业
     * @return
     */
    @GetMapping("/isRelated")
    public Result getUsers() {
        Boolean isRelated = userService.isRelated();
        return isRelated  ? Result.success() : Result.error(MessageConstant.NO_RELATED_COMPANY);
    }

    /**
     * 更新密码
     * @param oldPwd
     * @param newPwd
     * @return
     */
    @PutMapping("/pwd")
    public Result updataPwd(String oldPwd, String newPwd){
        log.info("更新密码:{},{}", oldPwd, newPwd);
        Boolean result = userService.updatePwd(oldPwd, newPwd);
        return result ? Result.success() : Result.error("旧密码错误");
    }
}
